package com.jiaai.cloud.user.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jiaai.cloud.base.exception.ServiceException;
import com.jiaai.cloud.base.page.FrontPage;
import com.jiaai.cloud.base.util.RestResultGenerator;
import com.jiaai.cloud.live.entity.TAnchor;
import com.jiaai.cloud.user.entity.TUserIdentity;
import com.jiaai.cloud.user.entity.TUserIdentitySearch;
import com.jiaai.cloud.user.service.ITUserIdentityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 用户实名验证 前端控制器
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2017-08-01
 */
@Controller
@RequestMapping("/api/manage/tUserIdentity")
public class TUserIdentityController {

    @Autowired
    private ITUserIdentityService itUserIdentityService;

    @RequestMapping(value = "/findByAll", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object findByAll(TUserIdentitySearch search) throws ServiceException {
        try {
            EntityWrapper wrapper=new EntityWrapper();
            if(search.getStatus()!=null){
                wrapper.eq("status",search.getStatus());
            }
            return RestResultGenerator.genSuccessResult(itUserIdentityService.findFully(search.getPagePlus(),wrapper));
        } catch (Exception e) {
            throw new ServiceException("查询失敗", e.getMessage());
        }
    }

    //通过改anchorId改status状态
    @RequestMapping(value = "/changeStatus/{id}/{status}", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object changeStatus(@PathVariable("id") long id, @PathVariable("status") Integer status) throws ServiceException {
        try {
            TUserIdentity tUserIdentity = new TUserIdentity();
            tUserIdentity.setId(id);
            tUserIdentity.setStatus(status);
            itUserIdentityService.updateById(tUserIdentity);
            return RestResultGenerator.genSuccessResult();
        }catch (Exception e) {
            throw new ServiceException("修改失敗", e.getMessage());
        }
    }


    //删
    @RequestMapping(value ="/deleteId/{id}", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public Object deleteId(@PathVariable("id") Integer id) throws ServiceException {
        try {
            itUserIdentityService.deleteById(id);
            return RestResultGenerator.genSuccessResult();
        } catch (Exception e) {
            throw new ServiceException("删除失敗", e.getMessage());
        }
    }



	
}
